package com.github.calvin.ui;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.github.calvin.R;
import com.github.calvin.util.SystemConst;


public class SplashActivity extends Activity {

    private ViewFlipper viewFlipper;
    private float startX;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        //delay Launch 1
//        new Handler().postDelayed(new Runnable() {
//
//            @Override
//            public void run() {
//                Intent pullRefreshIntent = new Intent(SplashActivity.this, PullToRefreshListActivity.class);
//                startActivity(pullRefreshIntent);
//                finish();
//            }
//        }, SystemConst.SPLISH_DISPLAY_LENGTH);

        viewFlipper = (ViewFlipper) findViewById(R.id.viewFliper);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startX = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                if (event.getX() < startX) {// from right to left
                    Log.v("--->>", "" + event.getFlags());
                    viewFlipper.setInAnimation(SplashActivity.this, R.anim.push_right_in);
                    viewFlipper.setOutAnimation(SplashActivity.this, R.anim.push_left_out);
                    if (viewFlipper.getCurrentView().getTag().equals("8")) {
                        Toast.makeText(getApplicationContext(), "End Of Animations", Toast.LENGTH_SHORT).show();
                        break;
                    }
                    viewFlipper.showNext();

                } else {
                    Log.v("---<<", "" + event.getFlags());
                    viewFlipper.setInAnimation(SplashActivity.this, R.anim.push_left_in);
                    viewFlipper.setOutAnimation(SplashActivity.this, R.anim.push_right_out);
                    if (viewFlipper.getCurrentView().getTag().equals("1")) {
                        Toast.makeText(getApplicationContext(), "Please Scroll left", Toast.LENGTH_SHORT).show();
                        break;
                    }
                    viewFlipper.showPrevious();
                }
                break;
        }
        return super.onTouchEvent(event);
    }
}
